package cn.iocoder.yudao.module.spark.service.impl;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.digital.controller.admin.csc.vo.CscSaveReqVO;
import cn.iocoder.yudao.module.digital.controller.admin.projects.vo.ProjectsSaveReqVO;
import cn.iocoder.yudao.module.digital.controller.admin.thesis.vo.ThesisSaveReqVO;
import cn.iocoder.yudao.module.spark.service.AIService;
import cn.iocoder.yudao.module.spark.util.ApiAuthUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import cn.iocoder.yudao.module.digital.controller.admin.competition.vo.CompetitionSaveReqVO;
import java.io.*;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Slf4j
@Service
public class AISericeImpl implements AIService {
    @Value("${spark.appid}")
    private String appid;
    @Value("${spark.api-key}")
    private String apiKey;
    @Value("${spark.api-secret}")
    private String apiSecret;
    private static final String HOST_URL = "https://spark-api.cn-huabei-1.xf-yun.com/v2.1/image";
    private static final String uploadUrl = "https://chatdoc.xfyun.cn/openapi/v1/file/upload";
    private static final String chatUrl = "wss://chatdoc.xfyun.cn/openapi/chat";
    private OkHttpClient client = new OkHttpClient.Builder().build();

    @Autowired
    private ApiAuthUtil apiAuthUtil;

    private List<String> evidenceUrl;

    @Transactional
    @Override
    public CommonResult<Integer> recognizeCompetitionImage(MultipartFile file, String question) throws Exception {
        evidenceUrl=new ArrayList<>();
        evidenceUrl.add(file.getOriginalFilename());

        // 1. 保存图片到临时文件
        File tempFile = File.createTempFile("sparkimg", ".png");
        file.transferTo(tempFile);
        // 2. 构造历史对话
        List<RoleContent> historyList = new ArrayList<>();
        // 添加图片
        RoleContent imageContent = new RoleContent();
        imageContent.role = "user";
        imageContent.content = Base64.getEncoder().encodeToString(apiAuthUtil.readFile(tempFile.getAbsolutePath()));
        imageContent.content_type = "image";
        historyList.add(imageContent);
        // 添加问题
        RoleContent textContent = new RoleContent();
        textContent.role = "user";
        textContent.content = question;
        textContent.content_type = "text";
        historyList.add(textContent);
        // 3. 构造请求体
        JSONObject header = new JSONObject();
        header.put("app_id", appid);
        header.put("uid", UUID.randomUUID().toString().substring(0, 10));
        JSONObject parameter = new JSONObject();
        JSONObject chat = new JSONObject();
        chat.put("domain", "imagev3");
        chat.put("temperature", 0.8);
        chat.put("max_tokens", 4096);
        chat.put("top_k", 6);
        chat.put("auditing", "default");
        parameter.put("chat", chat);
        JSONObject payload = new JSONObject();
        JSONObject message = new JSONObject();
        JSONArray textArr = new JSONArray();
        for (RoleContent rc : historyList) {
            JSONObject obj = new JSONObject();
            obj.put("role", rc.role);
            obj.put("content", rc.content);
            obj.put("content_type", rc.content_type);
            textArr.add(obj);
        }
        message.put("text", textArr);
        payload.put("message", message);
        JSONObject requestJson = new JSONObject();
        requestJson.put("header", header);
        requestJson.put("parameter", parameter);
        requestJson.put("payload", payload);
        // 4. 鉴权URL
        String authUrl = apiAuthUtil.getAuthUrl(HOST_URL, apiKey, apiSecret);
        String wsUrl = authUrl.replace("http://", "ws://").replace("https://", "wss://");
        // 5. WebSocket通信
        CountDownLatch latch = new CountDownLatch(1);
        StringBuilder result = new StringBuilder();
        Request request = new Request.Builder().url(wsUrl).build();
        WebSocket ws = client.newWebSocket(request, new WebSocketListener() {
            @Override
            public void onOpen(WebSocket webSocket, Response response) {
                webSocket.send(requestJson.toString());
            }
            @Override
            public void onMessage(WebSocket webSocket, String text) {
                JSONObject resp = JSONObject.parseObject(text);
                JSONObject header = resp.getJSONObject("header");
                if (header.getIntValue("code") != 0) {
                    result.append("发生错误，错误码为：").append(header.getIntValue("code"));
                    webSocket.close(1000, "");
                    latch.countDown();
                    return;
                }
                JSONArray textList = resp.getJSONObject("payload")
                        .getJSONObject("choices")
                        .getJSONArray("text");
                for (int i = 0; i < textList.size(); i++) {
                    result.append(textList.getJSONObject(i).getString("content"));
                }
                if (header.getIntValue("status") == 2) {
                    webSocket.close(1000, "");
                    latch.countDown();
                }
            }
            @Override
            public void onFailure(WebSocket webSocket, Throwable t, Response response) {
                result.append("WebSocket连接失败: ").append(t.getMessage());
                latch.countDown();
            }
        });
        latch.await(); // 等待响应
        log.info(result.toString());
        tempFile.delete(); // 删除临时文件
        Map<String, String> stringMap = apiAuthUtil.parseToMap(result.toString());
        CompetitionSaveReqVO competitionSaveReqVO = apiAuthUtil.mapToCompetitionRespVO(stringMap,evidenceUrl);
        return success(0).setMsg(JSON.toJSONString(competitionSaveReqVO));
    }

    @Override
    @Transactional
    public CommonResult<Integer> recognizeCompetitionPdf(MultipartFile file, String question) throws Exception {
        evidenceUrl=new ArrayList<>();
        evidenceUrl.add(file.getOriginalFilename());

        // 1. 上传PDF文档
        long ts = System.currentTimeMillis() / 1000;
        String signature = apiAuthUtil.getSignature(appid, apiSecret, ts);
        RequestBody body = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("file", file.getOriginalFilename(),
                        RequestBody.create(file.getBytes(), MediaType.parse("application/pdf")))
                .build();
        Request uploadRequest = new Request.Builder()
                .url(uploadUrl)
                .post(body)
                .addHeader("appId", appid)
                .addHeader("timestamp", String.valueOf(ts))
                .addHeader("signature", signature)
                .build();
        Response uploadResponse = client.newCall(uploadRequest).execute();
        String uploadRespStr = uploadResponse.body().string();
        JSONObject uploadRespJson = JSONObject.parseObject(uploadRespStr);
        if (uploadRespJson.getIntValue("code") != 0) {
            return CommonResult.error(uploadRespJson.getIntValue("code"), uploadRespJson.getString("message"));
        }
        String fileId = uploadRespJson.getJSONObject("data").getString("fileId");

        // 2. 轮询等待文件状态为 vectored
        String statusUrl = "https://chatdoc.xfyun.cn/openapi/v1/file/status";
        int maxTry = 30; // 最多轮询
        int interval = 3000; // 每次间隔3秒
        boolean vectored = false;
        for (int i = 0; i < maxTry; i++) {
            long statusTs = System.currentTimeMillis() / 1000;
            String statusSignature = apiAuthUtil.getSignature(appid, apiSecret, statusTs);
            RequestBody statusBody = new MultipartBody.Builder()
                    .setType(MultipartBody.FORM)
                    .addFormDataPart("fileIds", fileId)
                    .build();
            Request statusRequest = new Request.Builder()
                    .url(statusUrl)
                    .post(statusBody)
                    .addHeader("appId", appid)
                    .addHeader("timestamp", String.valueOf(statusTs))
                    .addHeader("signature", statusSignature)
                    .build();
            Response statusResponse = client.newCall(statusRequest).execute();
            String statusRespStr = statusResponse.body().string();
            JSONObject statusRespJson = JSONObject.parseObject(statusRespStr);
            if (statusRespJson.getIntValue("code") == 0) {
                JSONArray dataArr = statusRespJson.getJSONArray("data");
                if (dataArr != null && !dataArr.isEmpty()) {
                    String status = dataArr.getJSONObject(0).getString("fileStatus");
                    if ("vectored".equals(status)) {
                        vectored = true;
                        break;
                    }
                }
            }
            Thread.sleep(interval);
        }
        if (!vectored) {
            return CommonResult.error(500, "文件处理超时，请稍后重试");
        }

        // 3. WebSocket问答
        ts = System.currentTimeMillis() / 1000;
        signature = apiAuthUtil.getSignature(appid, apiSecret, ts);
        String wsUrl = chatUrl + "?appId=" + appid + "&timestamp=" + ts + "&signature=" + signature;
        CountDownLatch latch = new CountDownLatch(1);
        StringBuilder result = new StringBuilder();
        // 构造请求体
        JSONObject req = new JSONObject();
        req.put("fileIds", Collections.singletonList(fileId));
        req.put("topN", 3);
        JSONArray messages = new JSONArray();
        JSONObject msg = new JSONObject();
        msg.put("role", "user");
        msg.put("content", question);
        messages.add(msg);
        req.put("messages", messages);

        Request wsRequest = new Request.Builder().url(wsUrl).build();
        client.newWebSocket(wsRequest, new WebSocketListener() {
            @Override
            public void onOpen(WebSocket webSocket, Response response) {
                webSocket.send(req.toJSONString());
            }
            @Override
            public void onMessage(WebSocket webSocket, String text) {
                JSONObject obj = JSONObject.parseObject(text);
                String content = obj.getString("content");
                if (content != null) result.append(content);
                if (obj.getIntValue("status") == 2) {
                    webSocket.close(1000, "done");
                    latch.countDown();
                }
            }
            @Override
            public void onFailure(WebSocket webSocket, Throwable t, Response response) {
                result.append("WebSocket连接失败: ").append(t.getMessage());
                latch.countDown();
            }
        });
        latch.await(); // 等待响应
        log.info(result.toString());
        // 4. 解析AI返回内容，转为Map再封装VO
        Map<String, String> stringMap = apiAuthUtil.parseToMap(result.toString());
        CompetitionSaveReqVO competitionSaveReqVO = apiAuthUtil.mapToCompetitionRespVO(stringMap,evidenceUrl);
        return success(0).setMsg(JSON.toJSONString(competitionSaveReqVO));
    }

    @Override
    public CommonResult<Integer> recognizeProjects(MultipartFile file, String question) throws Exception{
        evidenceUrl=new ArrayList<>();
        evidenceUrl.add(file.getOriginalFilename());

        // 1. 上传PDF文档
        long ts = System.currentTimeMillis() / 1000;
        String signature = apiAuthUtil.getSignature(appid, apiSecret, ts);
        RequestBody body = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("file", file.getOriginalFilename(),
                        RequestBody.create(file.getBytes(), MediaType.parse("application/pdf")))
                .build();
        Request uploadRequest = new Request.Builder()
                .url(uploadUrl)
                .post(body)
                .addHeader("appId", appid)
                .addHeader("timestamp", String.valueOf(ts))
                .addHeader("signature", signature)
                .build();
        Response uploadResponse = client.newCall(uploadRequest).execute();
        String uploadRespStr = uploadResponse.body().string();
        JSONObject uploadRespJson = JSONObject.parseObject(uploadRespStr);
        if (uploadRespJson.getIntValue("code") != 0) {
            return CommonResult.error(uploadRespJson.getIntValue("code"), uploadRespJson.getString("message"));
        }
        String fileId = uploadRespJson.getJSONObject("data").getString("fileId");

        // 2. 轮询等待文件状态为 vectored
        String statusUrl = "https://chatdoc.xfyun.cn/openapi/v1/file/status";
        int maxTry = 30; // 最多轮询
        int interval = 3000; // 每次间隔3秒
        boolean vectored = false;
        for (int i = 0; i < maxTry; i++) {
            long statusTs = System.currentTimeMillis() / 1000;
            String statusSignature = apiAuthUtil.getSignature(appid, apiSecret, statusTs);
            RequestBody statusBody = new MultipartBody.Builder()
                    .setType(MultipartBody.FORM)
                    .addFormDataPart("fileIds", fileId)
                    .build();
            Request statusRequest = new Request.Builder()
                    .url(statusUrl)
                    .post(statusBody)
                    .addHeader("appId", appid)
                    .addHeader("timestamp", String.valueOf(statusTs))
                    .addHeader("signature", statusSignature)
                    .build();
            Response statusResponse = client.newCall(statusRequest).execute();
            String statusRespStr = statusResponse.body().string();
            JSONObject statusRespJson = JSONObject.parseObject(statusRespStr);
            if (statusRespJson.getIntValue("code") == 0) {
                JSONArray dataArr = statusRespJson.getJSONArray("data");
                if (dataArr != null && !dataArr.isEmpty()) {
                    String status = dataArr.getJSONObject(0).getString("fileStatus");
                    if ("vectored".equals(status)) {
                        vectored = true;
                        break;
                    }
                }
            }
            Thread.sleep(interval);
        }
        if (!vectored) {
            return CommonResult.error(500, "文件处理超时，请稍后重试");
        }

        // 3. WebSocket问答
        ts = System.currentTimeMillis() / 1000;
        signature = apiAuthUtil.getSignature(appid, apiSecret, ts);
        String wsUrl = chatUrl + "?appId=" + appid + "&timestamp=" + ts + "&signature=" + signature;
        CountDownLatch latch = new CountDownLatch(1);
        StringBuilder result = new StringBuilder();
        // 构造请求体
        JSONObject req = new JSONObject();
        req.put("fileIds", Collections.singletonList(fileId));
        req.put("topN", 3);
        JSONArray messages = new JSONArray();
        JSONObject msg = new JSONObject();
        msg.put("role", "user");
        msg.put("content", question);
        messages.add(msg);
        req.put("messages", messages);

        Request wsRequest = new Request.Builder().url(wsUrl).build();
        client.newWebSocket(wsRequest, new WebSocketListener() {
            @Override
            public void onOpen(WebSocket webSocket, Response response) {
                webSocket.send(req.toJSONString());
            }
            @Override
            public void onMessage(WebSocket webSocket, String text) {
                JSONObject obj = JSONObject.parseObject(text);
                String content = obj.getString("content");
                if (content != null) result.append(content);
                if (obj.getIntValue("status") == 2) {
                    webSocket.close(1000, "done");
                    latch.countDown();
                }
            }
            @Override
            public void onFailure(WebSocket webSocket, Throwable t, Response response) {
                result.append("WebSocket连接失败: ").append(t.getMessage());
                latch.countDown();
            }
        });
        latch.await(); // 等待响应
        log.info(result.toString());
        // 4. 解析AI返回内容，转为Map再封装VO
        Map<String, String> stringMap = apiAuthUtil.parseToMap(result.toString());
        ProjectsSaveReqVO projectsSaveReqVO = apiAuthUtil.mapToProjectsSaveReqVO(stringMap,evidenceUrl);
        return success(0).setMsg(JSON.toJSONString(projectsSaveReqVO));
    }

    @Override
    public CommonResult<Integer> recognizeThesis(MultipartFile file, String question) throws Exception {
        evidenceUrl=new ArrayList<>();
        evidenceUrl.add(file.getOriginalFilename());

        // 1. 上传PDF文档
        long ts = System.currentTimeMillis() / 1000;
        String signature = apiAuthUtil.getSignature(appid, apiSecret, ts);
        RequestBody body = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("file", file.getOriginalFilename(),
                        RequestBody.create(file.getBytes(), MediaType.parse("application/pdf")))
                .build();
        Request uploadRequest = new Request.Builder()
                .url(uploadUrl)
                .post(body)
                .addHeader("appId", appid)
                .addHeader("timestamp", String.valueOf(ts))
                .addHeader("signature", signature)
                .build();
        Response uploadResponse = client.newCall(uploadRequest).execute();
        String uploadRespStr = uploadResponse.body().string();
        JSONObject uploadRespJson = JSONObject.parseObject(uploadRespStr);
        if (uploadRespJson.getIntValue("code") != 0) {
            return CommonResult.error(uploadRespJson.getIntValue("code"), uploadRespJson.getString("message"));
        }
        String fileId = uploadRespJson.getJSONObject("data").getString("fileId");

        // 2. 轮询等待文件状态为 vectored
        String statusUrl = "https://chatdoc.xfyun.cn/openapi/v1/file/status";
        int maxTry = 30; // 最多轮询
        int interval = 3000; // 每次间隔3秒
        boolean vectored = false;
        for (int i = 0; i < maxTry; i++) {
            long statusTs = System.currentTimeMillis() / 1000;
            String statusSignature = apiAuthUtil.getSignature(appid, apiSecret, statusTs);
            RequestBody statusBody = new MultipartBody.Builder()
                    .setType(MultipartBody.FORM)
                    .addFormDataPart("fileIds", fileId)
                    .build();
            Request statusRequest = new Request.Builder()
                    .url(statusUrl)
                    .post(statusBody)
                    .addHeader("appId", appid)
                    .addHeader("timestamp", String.valueOf(statusTs))
                    .addHeader("signature", statusSignature)
                    .build();
            Response statusResponse = client.newCall(statusRequest).execute();
            String statusRespStr = statusResponse.body().string();
            JSONObject statusRespJson = JSONObject.parseObject(statusRespStr);
            if (statusRespJson.getIntValue("code") == 0) {
                JSONArray dataArr = statusRespJson.getJSONArray("data");
                if (dataArr != null && !dataArr.isEmpty()) {
                    String status = dataArr.getJSONObject(0).getString("fileStatus");
                    if ("vectored".equals(status)) {
                        vectored = true;
                        break;
                    }
                }
            }
            Thread.sleep(interval);
        }
        if (!vectored) {
            return CommonResult.error(500, "文件处理超时，请稍后重试");
        }

        // 3. WebSocket问答
        ts = System.currentTimeMillis() / 1000;
        signature = apiAuthUtil.getSignature(appid, apiSecret, ts);
        String wsUrl = chatUrl + "?appId=" + appid + "&timestamp=" + ts + "&signature=" + signature;
        CountDownLatch latch = new CountDownLatch(1);
        StringBuilder result = new StringBuilder();
        // 构造请求体
        JSONObject req = new JSONObject();
        req.put("fileIds", Collections.singletonList(fileId));
        req.put("topN", 3);
        JSONArray messages = new JSONArray();
        JSONObject msg = new JSONObject();
        msg.put("role", "user");
        msg.put("content", question);
        messages.add(msg);
        req.put("messages", messages);

        Request wsRequest = new Request.Builder().url(wsUrl).build();
        client.newWebSocket(wsRequest, new WebSocketListener() {
            @Override
            public void onOpen(WebSocket webSocket, Response response) {
                webSocket.send(req.toJSONString());
            }
            @Override
            public void onMessage(WebSocket webSocket, String text) {
                JSONObject obj = JSONObject.parseObject(text);
                String content = obj.getString("content");
                if (content != null) result.append(content);
                if (obj.getIntValue("status") == 2) {
                    webSocket.close(1000, "done");
                    latch.countDown();
                }
            }
            @Override
            public void onFailure(WebSocket webSocket, Throwable t, Response response) {
                result.append("WebSocket连接失败: ").append(t.getMessage());
                latch.countDown();
            }
        });
        latch.await(); // 等待响应
        log.info(result.toString());
        // 4. 解析AI返回内容，转为Map再封装VO
        Map<String, String> stringMap = apiAuthUtil.parseToMap(result.toString());
        ThesisSaveReqVO thesisSaveReqVO = apiAuthUtil.mapToThesisSaveReqVO(stringMap,evidenceUrl);
        return success(0).setMsg(JSON.toJSONString(thesisSaveReqVO));
    }

    @Override
    public CommonResult<Integer> recognizeCSC(MultipartFile file, String question) throws Exception {
        evidenceUrl=new ArrayList<>();
        evidenceUrl.add(file.getOriginalFilename());

        // 1. 上传PDF文档
        long ts = System.currentTimeMillis() / 1000;
        String signature = apiAuthUtil.getSignature(appid, apiSecret, ts);
        RequestBody body = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("file", file.getOriginalFilename(),
                        RequestBody.create(file.getBytes(), MediaType.parse("application/pdf")))
                .build();
        Request uploadRequest = new Request.Builder()
                .url(uploadUrl)
                .post(body)
                .addHeader("appId", appid)
                .addHeader("timestamp", String.valueOf(ts))
                .addHeader("signature", signature)
                .build();
        Response uploadResponse = client.newCall(uploadRequest).execute();
        String uploadRespStr = uploadResponse.body().string();
        JSONObject uploadRespJson = JSONObject.parseObject(uploadRespStr);
        if (uploadRespJson.getIntValue("code") != 0) {
            return CommonResult.error(uploadRespJson.getIntValue("code"), uploadRespJson.getString("message"));
        }
        String fileId = uploadRespJson.getJSONObject("data").getString("fileId");

        // 2. 轮询等待文件状态为 vectored
        String statusUrl = "https://chatdoc.xfyun.cn/openapi/v1/file/status";
        int maxTry = 30; // 最多轮询
        int interval = 3000; // 每次间隔3秒
        boolean vectored = false;
        for (int i = 0; i < maxTry; i++) {
            long statusTs = System.currentTimeMillis() / 1000;
            String statusSignature = apiAuthUtil.getSignature(appid, apiSecret, statusTs);
            RequestBody statusBody = new MultipartBody.Builder()
                    .setType(MultipartBody.FORM)
                    .addFormDataPart("fileIds", fileId)
                    .build();
            Request statusRequest = new Request.Builder()
                    .url(statusUrl)
                    .post(statusBody)
                    .addHeader("appId", appid)
                    .addHeader("timestamp", String.valueOf(statusTs))
                    .addHeader("signature", statusSignature)
                    .build();
            Response statusResponse = client.newCall(statusRequest).execute();
            String statusRespStr = statusResponse.body().string();
            JSONObject statusRespJson = JSONObject.parseObject(statusRespStr);
            if (statusRespJson.getIntValue("code") == 0) {
                JSONArray dataArr = statusRespJson.getJSONArray("data");
                if (dataArr != null && !dataArr.isEmpty()) {
                    String status = dataArr.getJSONObject(0).getString("fileStatus");
                    if ("vectored".equals(status)) {
                        vectored = true;
                        break;
                    }
                }
            }
            Thread.sleep(interval);
        }
        if (!vectored) {
            return CommonResult.error(500, "文件处理超时，请稍后重试");
        }

        // 3. WebSocket问答
        ts = System.currentTimeMillis() / 1000;
        signature = apiAuthUtil.getSignature(appid, apiSecret, ts);
        String wsUrl = chatUrl + "?appId=" + appid + "&timestamp=" + ts + "&signature=" + signature;
        CountDownLatch latch = new CountDownLatch(1);
        StringBuilder result = new StringBuilder();
        // 构造请求体
        JSONObject req = new JSONObject();
        req.put("fileIds", Collections.singletonList(fileId));
        req.put("topN", 3);
        JSONArray messages = new JSONArray();
        JSONObject msg = new JSONObject();
        msg.put("role", "user");
        msg.put("content", question);
        messages.add(msg);
        req.put("messages", messages);

        Request wsRequest = new Request.Builder().url(wsUrl).build();
        client.newWebSocket(wsRequest, new WebSocketListener() {
            @Override
            public void onOpen(WebSocket webSocket, Response response) {
                webSocket.send(req.toJSONString());
            }
            @Override
            public void onMessage(WebSocket webSocket, String text) {
                JSONObject obj = JSONObject.parseObject(text);
                String content = obj.getString("content");
                if (content != null) result.append(content);
                if (obj.getIntValue("status") == 2) {
                    webSocket.close(1000, "done");
                    latch.countDown();
                }
            }
            @Override
            public void onFailure(WebSocket webSocket, Throwable t, Response response) {
                result.append("WebSocket连接失败: ").append(t.getMessage());
                latch.countDown();
            }
        });
        latch.await(); // 等待响应
        log.info(result.toString());
        // 4. 解析AI返回内容，转为Map再封装VO
        Map<String, String> stringMap = apiAuthUtil.parseToMap(result.toString());
        CscSaveReqVO cscSaveReqVO = apiAuthUtil.mapToCscSaveReqVO(stringMap,evidenceUrl);
        return success(0).setMsg(JSON.toJSONString(cscSaveReqVO));
    }

    // 对话内容结构体
    static class RoleContent {
        public String role;
        public String content;
        public String content_type;
    }


}

